<?php
include( "agent/onlinebet_header2.php" );
if ($curruser['acl'] != 255)
{
    $userlist = GetUserList($curruser['id']);
    if ($userlist == "")
    {
        $ui->showErrorPage("<p>还没有建立会员！</p>");
        exit();
    }
}
$g_disk_code = array(1 => "a", 2 => "b", 3 => "c", 4 => "d");
$disk_code = "a";
$diskStr = "";
if (0 < $disk)
{
    $disk_code = $g_disk_code[$disk];
    $diskStr = $disk_code;
}
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h($lotto_id);
$colors = array("", "red", "blue", "green");
$dataTotalArr = array();
$showDataArr = array();
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
switch ($bets)
{
    case 0 :
        $bettypeStr = "1006, 1007, 34, 35";
        $listbetmod = 0;
        $betsGameA = "1006";
        $betsGameB = "1007";
        $betsRatePreA = "21";
        $betsRatePreB = "22";
        break;
    case 1 :
        $bettypeStr = "21, 22, 34, 35";
        $listbetmod = 0;
        $betsGameA = "21";
        $betsGameB = "22";
        $betsRatePreA = "21";
        $betsRatePreB = "22";
        break;
    case 2 :
        $bettypeStr = "37, 38, 34, 35";
        $listbetmod = 0;
        $betsGameA = "37";
        $betsGameB = "38";
        $betsRatePreA = "37";
        $betsRatePreB = "38";
        break;
    default :
        $bettypeStr = "1006, 1007, 34, 35";
        $listbetmod = 0;
        $betsGameA = "1006";
        $betsGameB = "1007";
        $betsRatePreA = "21";
        $betsRatePreB = "22";
        break;
}
$i = 1;
while ($i < 13)
{
    $showDataArr[$betsGameA][$i] = array("numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "");
    ++$i;
}
$i = 1;
while ($i < 11)
{
    $showDataArr[$betsGameB][$i] = array("numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "");
    ++$i;
}
$dataTotalArr[$betsGameA] = array("bettype" => $betsGameA, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
$dataTotalArr[$betsGameB] = array("bettype" => $betsGameB, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
$totalBetTyprArr = array($betsGameA, $betsGameB, 34, 35);
$totalRs = $BetTotal_6h->getDataListTotal($lotto_id, $bettypeStr, $showid, $split, $diskStr);
while (!$totalRs->eof)
{
    $tempIdx = $totalRs->f['bettype'];
    $dataTotalArr[$tempIdx] = $totalRs->f;
    $totalRs->next();
}
$totalRs->close();
$sql = $BetTotal_6h->getDataListByNumSsSQL($lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod);
$rs = getdb($sql);
$updatetime = systime() - 30;
while (!$rs->eof)
{
    $bettype = $rs->f['bettype'];
    $winlost = $dataTotalArr[$bettype]['amount'] - $rs->f['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$rs->f[1]]['back2'];
    $i = $rs->f['numbers'];
    $showDataArr[$bettype][$i]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$bettype][$i]['amount'] = $rs->f['amount'];
    $showDataArr[$bettype][$i]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$bettype][$i]['rate'] = $rs->f['rate'];
    $showDataArr[$bettype][$i]['back1'] = $rs->f['back1'];
    $showDataArr[$bettype][$i]['back2'] = $rs->f['back2'];
    $showDataArr[$bettype][$i]['winlost'] = $winlost;
    if ($updatetime < $rs->f['updatetime'])
    {
        $showDataArr[$bettype][$i]['namount'] = " class=\"namount\"";
    }
    $rs->next();
}
$rs->close();
if ($ratemod == 0)
{
    $rs = getdb("select * from rate1{$disk_code} where lotto_id={$lotto_id}");
    if ($theacl == 255)
    {
        $rs1 = get_srates_data($curruser['id'], $lotto_id, 21);
        $i = 1;
        while ($i <= 12)
        {
            $showDataArr[$betsGameA][$i]['rate'] = $rs->f["r{$betsRatePreA}_{$i}"] - 0;
            ++$i;
        }
        $i = 1;
        while ($i <= 10)
        {
            $showDataArr[$betsGameB][$i]['rate'] = $rs->f["r{$betsRatePreB}_{$i}"] - 0;
            ++$i;
        }
    }
    else
    {
        $rsu = get_srates_data($curruser['id'], $lotto_id, 21);
        $i = 1;
        while ($i <= 12)
        {
            $showDataArr[$betsGameA][$i]['rate'] = $rs->f["r{$betsRatePreA}_{$i}"] - $rsu->f["r21_{$i}"] - 0;
            ++$i;
        }
        $i = 1;
        while ($i <= 10)
        {
            $showDataArr[$betsGameB][$i]['rate'] = $rs->f["r{$betsRatePreB}_{$i}"] - $rsu->f["r22_{$i}"] - 0;
            ++$i;
        }
        $rsu->close();
    }
    $rs->close();
}
$list = "";
$i = 1;
while ($i <= 12)
{
    if ($i % 4 == 1)
    {
        $list .= "<tr class=td2>";
    }
    $list .= "<td class=td6 align=center>" . $g_chinayear[$i] . "</td>";
    if (0 < $showDataArr[$betsGameA][$i]['totalnum'])
    {
        $list .= "<td align=right nowrap>" . $showDataArr[$betsGameA][$i]['totalnum'] . "</td>";
        $list .= "<td align=right nowrap " . $showDataArr[$betsGameA][$i]['namount'] . "><a href=" . get_listurl($open, $betsGameA, $i) . ">" . round($showDataArr[$betsGameA][$i]['amount']) . "</a></td>";
    }
    else
    {
        $list .= "<td align=right> 0</td>";
        $list .= "<td align=right> 0</td>";
        $showDataArr[$betsGameA][$i]['winlost'] = $dataTotalArr[$betsGameA]['amount'] - $dataTotalArr[$betsGameA]['back1'] + $dataTotalArr[$betsGameA]['back2'];
    }
    $list .= "<td align=right> " . $showDataArr[$betsGameA][$i]['rate'] . "</td>";
    if ($showDataArr[$betsGameA][$i]['winlost'] < 0)
    {
        $list .= "<td align=right nowrap><font color='#EE2200'>" . round($showDataArr[$betsGameA][$i]['winlost']) . "</font></td>";
    }
    else
    {
        $list .= "<td align=right nowrap><font color='#00AA22'>" . round($showDataArr[$betsGameA][$i]['winlost']) . "</font></td>";
    }
    ++$i;
}
$tpl->set("list21", $list);
$tpl->set("list21sum", "合计：<b>" . intval($dataTotalArr[$betsGameA]['totalnum']) . "</b> 笔，金额：<b>" . round($dataTotalArr[$betsGameA]['amount']) . "</b>");
$list = "";
$i = 1;
while ($i <= 10)
{
    if ($i % 5 == 1)
    {
        $list .= "<tr class=td2>";
    }
    $list .= "<td class=td6 align=center>" . substr($i, 0 - 1) . " 尾</td>";
    if (0 < $showDataArr[$betsGameB][$i]['totalnum'])
    {
        $list .= "<td align=right nowrap>" . $showDataArr[$betsGameB][$i]['totalnum'] . "</td>";
        $list .= "<td align=right nowrap" . $showDataArr[$betsGameB][$i]['namount'] . "><a href=" . get_listurl($open, $betsGameB, $i) . ">" . round($showDataArr[$betsGameB][$i]['amount']) . "</a></td>";
    }
    else
    {
        $list .= "<td align=right> 0</td>";
        $list .= "<td align=right> 0</td>";
        $showDataArr[$betsGameB][$i]['winlost'] = $dataTotalArr[$betsGameB]['amount'] - $dataTotalArr[$betsGameB]['back1'] + $dataTotalArr[$betsGameB]['back2'];
    }
    $list .= "<td align=right> " . $showDataArr[$betsGameB][$i]['rate'] . "</td>";
    if ($showDataArr[$betsGameB][$i]['winlost'] < 0)
    {
        $list .= "<td align=right nowrap><font color='#EE2200'>" . round($showDataArr[$betsGameB][$i]['winlost']) . "</font></td>";
    }
    else
    {
        $list .= "<td align=right nowrap><font color='#00AA22'>" . round($showDataArr[$betsGameB][$i]['winlost']) . "</font></td>";
    }
    ++$i;
}
$tpl->set("list22", $list);
$tpl->set("list22sum", "合计：<b>" . intval($dataTotalArr[$betsGameB]['totalnum']) . "</b> 笔，金额：<b>" . round($dataTotalArr[$betsGameB]['amount']) . "</b>");

$rateurl = preg_replace("/bets=\\d?/", "", $_SERVER['REQUEST_URI']);
$rlist = "&nbsp;&nbsp;&nbsp;赔率：<select name=ratemod onchange=\"location.replace('{$rateurl}&ratemod='+this.value)\">";
$rlist .= "<option value=0" . ( $ratemod == 0 ? " selected" : "" ) . ">目前赔率";
$rlist .= "<option value=1" . ( $ratemod == 1 ? " selected" : "" ) . ">平均赔率";
$rlist .= "<option value=2" . ( $ratemod == 2 ? " selected" : "" ) . ">输赢赔率";
$rlist .= "</select>";
$tpl->set("mess", $rlist);
$tpl->load("main", "onlinebet3.htm");
$tpl->show("main");
$ui->footer();
?>